package com.kingschan.jeasytag.sql.parse;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.kingschan.jeasytag.enums.DbType;
/**
 * 
 *@author kingschan
 *date:2013-4-24
 *{filterfield:"logpwd",relationship:"and",Operator:"eq",value:"f"}
 */
public abstract class AbstractAnalysis implements FieldTypeAnalysis{
	protected static  Map<String,String> Operator;
	static{
		Operator= new HashMap<String, String>();
		Operator.put("eq", "=");
		Operator.put("Less", "<");
		Operator.put("Greater", ">");
		Operator.put("GreaterEq", ">=");
		Operator.put("LessEq", "<=");
		Operator.put("notEq", "<>");
		Operator.put("Contain", "like '%${value}%'");
		Operator.put("likeLeft", "like '${value}%'");
		Operator.put("likeRight", "like '%${value}'");
		Operator.put("in", "in");
	}
	@Override
	public String Analysis(JSONObject filter, DbType dbtype) throws Exception {
		String product=null;
		switch (dbtype) {
		case MYSQL:
			product=this.mysqlAnalysis(filter);
			break;
		case SQLSERVER:
			product=this.sqlserverAnalysis(filter);
			break;
		case ORACLE:
			product=this.oracleAnalysis(filter);
			break;
		default:			
			break;
		}
		return product;
	}
	/**
	 * sqlserverAnalysis
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	protected abstract String sqlserverAnalysis(JSONObject filter)throws Exception;
	/**
	 * mysqlAnalysis
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	protected abstract String mysqlAnalysis(JSONObject filter)throws Exception;
	/**
	 * oracleAnalysis
	 * @param filter
	 * @return
	 * @throws Exception
	 */
	protected abstract String oracleAnalysis(JSONObject filter)throws Exception;
}
